package com.kasinf.sample.mybatis.trans;

import cn.hutool.core.convert.Convert;
import com.kasinf.framework.common.util.object.BeanUtils;
import com.kasinf.sample.mybatis.dal.dataobject.UserDO;
import com.kasinf.sample.mybatis.service.UserService;
import com.kasinf.sample.mybatis.trans.dto.UserDTO;
import lombok.RequiredArgsConstructor;
import org.dromara.core.trans.anno.AutoTrans;
import org.dromara.trans.service.AutoTransable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author : Kaiser
 * @Date: 2025/5/19  16:53
 */
@Service
@RequiredArgsConstructor
@AutoTrans(namespace = "user", fields = {"nickname"}, isAccess = true)
public class UserTransService implements AutoTransable<UserDTO> {

    private final UserService userService;

    @Override
    public List<UserDTO> selectByIds(List<?> ids) {
        List<UserDO> userDOS = userService.getFromCache(Convert.toList(Long.class, ids));
        return BeanUtils.toBean(userDOS, UserDTO.class);
    }

    @Override
    public UserDTO selectById(Object id) {
        if (id == null) {
            return null;
        }
        UserDO userDO = userService.getFromCache(Convert.toLong(id));
        return BeanUtils.toBean(userDO, UserDTO.class);
    }
}
